import requests
import urllib3
import time
import logging
import http.client


# http.client.HTTPConnection.debuglevel = logging.DEBUG

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

CSRFP_TOKEN = "csrfp_token"
session = requests.Session()
session.verify = False

def printResp(resp):
    print(resp,resp.url)
    if len(resp.text) < 1024: print(resp.text)
    if resp.status_code != 200:
        for i in resp:
            print(i)

resp = session.post("https://10.206.64.224/middleware_rev/handlers/login/login.php", data={"username": "admin", "password": "Admin1234!", "sessionsetting": "private"})
printResp(resp)


resp = session.get("https://10.206.64.224/middleware_rev/handlers/upgrade_upload/upgrade_upload.php?action=get_version&_=%d"%int(time.time()))
printResp(resp)

resp = session.post("https://10.206.64.224/middleware_rev/handlers/rdqa/control_sshd.php",data={'action':'start','csrfp_token':session.cookies.get(CSRFP_TOKEN)})
printResp(resp)

resp = session.post("https://10.206.64.224/middleware_rev/handlers/proxy/proxy.php/platform/systemsetting/multisettings?action=query")
resp = session.get("https://10.206.64.224/middleware_rev/handlers/login/logoff.php")
printResp(resp)
# with open('a.html','w') as f:
#     for i in resp:
#         f.write(str(i))
